package adv5.exec;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Company implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// 公司有公司名称，注册地址，电话，经营范围等属性，
	private String name = "蓝翔有限公司";
	private String address = "安徽";
	private String tel = "10089";
	private String fanwei = "挖土";
	// 员工列表信息
	private List<Staff> list = new ArrayList<>(0);

	public Company() {

	}

//公司有招聘员工（要求工号不能重复），有输出员工信息，以及辞退员工，和统计公司人数的方法
	public Company(String name, String address, String tel, String fanwei) {
		super();
		this.name = name;
		this.address = address;
		this.tel = tel;
		this.fanwei = fanwei;
	}

//公司信息
	public void companyShow() {
		System.out
				.println("这个公司的名称是:" + this.name + "，地址：" + this.address + ",电话：" + this.tel + ",经营范围：" + this.fanwei);
		System.out.println("---员工列表-------");
		for (Staff s : list)
			s.Staffshow();
	}

	// 员工信息
	public void showStaff() {
		for (Object yuangong : list) {
			Staff s = (Staff) yuangong;
			s.Staffshow();
		}

	}

	// 招聘员工
	public void addstaff(Staff ren) {
		if ((list.contains(ren))) {
			System.out.println("录用失败！（员工信息重复了）");
			return;
		}
//		for (Staff staff : list) {
//			if (staff.getWorkNum().equalsIgnoreCase(ren.getWorkNum())) {
//				System.out.println("录用失败！（员工信息重复了）");
//				return;
//			}
//		}
		list.add(ren);
		System.out.println("录用成功！");
	}

	// 辞退员工
	public boolean dismiss(String gonghao) {
		for (int i = 0; i < list.size(); i++) {
			Staff s1 = (Staff) list.get(i);
			if (s1.getWorkNum().equals(gonghao)) {
				list.remove(i);
				return true;

			}
		}
		return false;

	}

	// 统计公司总人数
	public int count() {
		return list.size();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getFanwei() {
		return fanwei;
	}

	public void setFanwei(String fanwei) {
		this.fanwei = fanwei;
	}
	/*
	 * public List<Staff> getList() { return list; }
	 * 
	 * public void setList(List<Staff> list) { this.list = list; }
	 */

	@Override
	public String toString() {
		return "Company [name=" + name + ", address=" + address + ", tel=" + tel + ", fanwei=" + fanwei + ", list="
				+ list + "]";
	}

}
